using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Bule.Malbilden.Forms
{
    public partial class AddUserForm : Form
    {
        public AddUserForm()
        {
            InitializeComponent();
        }

        public string UserName { get { return usernameTextbox.Text; } }
        public int Age { get { return Convert.ToInt32(ageTextbox.Text); } }
        public bool IsFemale { get { return femaleRadiobutton.Checked; } }
        public bool IsNursing { get { return nursingCheckbox.Checked; } }
        public bool IsPregnant { get { return pregnantCheckbox.Checked; } }


        private void usernameTextbox_TextChanged(object sender, EventArgs e)
        {
            UpdateControlEnabledState();
        }

        private void femaleRadiobutton_CheckedChanged(object sender, EventArgs e)
        {
            bool isFemale = femaleRadiobutton.Checked;
            nursingCheckbox.Enabled = isFemale;
            pregnantCheckbox.Enabled = isFemale;

            UpdateControlEnabledState();
        }

        private void ageTextbox_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Only allow numeric input:
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
                e.Handled = true;
        }

        private void AddUserForm_Load(object sender, EventArgs e)
        {
            nursingCheckbox.Enabled = false;
            pregnantCheckbox.Enabled = false;
        }

        private void UpdateControlEnabledState()
        {
            bool isValidDataGiven = !string.IsNullOrEmpty(usernameTextbox.Text) &&
                                    !string.IsNullOrEmpty(ageTextbox.Text) &&
                                    (femaleRadiobutton.Checked || maleRadiobutton.Checked);

            addButton.Enabled = isValidDataGiven;
        }

        private void ageTextbox_TextChanged(object sender, EventArgs e)
        {
            UpdateControlEnabledState();
        }

        private void maleRadiobutton_CheckedChanged(object sender, EventArgs e)
        {
            UpdateControlEnabledState();
        }
    }
}